Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Buildings With an Ocean View (medium)
Problem Statement
You are given an array heights of size n, representing the heights of n buildings.
The ocean is to the right of these buildings. A building has an ocean view if there are no taller buildings to its right.
The task is to find the indices(0-based) of all such buildings with an ocean view.
Examples
-
Example 1:
- Input:
[4, 3, 2, 1] - Expected Output:
[0, 1, 2, 3] - Justification: Each building is shorter than the one to its left, hence all have an ocean view.
- Input:
-
Example 2:
- Input:
[2, 3, 1, 4] - Expected Output:
[3] - Justification: Building at index 3 is the only one without taller buildings to their right.
- Input:
-
Example 3:
- Input:
[7, 4, 3, 2, 1, 4, 6, 3] - Expected Output:
[0, 6, 7] - Justification: Buildings at indices 0, 6, and 7 are the only ones without taller buildings to their right.
- Input:
Constraints:
- 1 <= heights.length <= 105
- 1 <= heights[i] <= 109
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Binary Tree Vertical Order Traversal
Solution: Buildings With an Ocean View
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself